home *** CD-ROM | disk | FTP | other *** search
/ Deutsche Edition 1 / Deutsche Edition 1.iso / amok / 011-020 / amok16 / memsystem / memsystem.def < prev    next >
Text File  |  1993-11-04  |  4KB  |  93 lines

  1. (**********************************************************************
  2.  
  3.     :Program.    MemSystem.def
  4.     :Contents.   convenient memory allocation procedures
  5.     :Author.     Nicolas Benezan [bne]
  6.     :Address.    Postwiesenstr. 2, D7000 Stuttgart 60
  7.     :Phone.      711/333679
  8.     :Copyright.  Public Domain
  9.     :Language.   Modula-2
  10.     :Translator. M2Amiga AMSoft 3.11
  11.     :Imports.    ErrorReq,TaskMemory [bne]
  12.     :History.    V1.0 [bne] 17.Jun.88 (private)
  13.     :History.    V1.1 [bne] 09.Jul.88 (+ TaskMem)
  14.     :History.    V1.2 [bne] 12.Jan.89 (ErrorReq items excluded)
  15.     :History.    V1.3 [bne] 04.Mar.89 (+ NoCareDeallocate(), Levels )
  16.  
  17. **********************************************************************)
  18.  
  19. DEFINITION MODULE MemSystem;
  20.  
  21. FROM SYSTEM     IMPORT ADDRESS;
  22.  
  23. TYPE    LevelKey; (* opaque to avoid manipulation *)
  24.  
  25. VAR     minMemory:LONGINT; (* Default=20kB *)
  26.         Hysteresis:LONGINT;(* Default=30kB *)
  27.  
  28. PROCEDURE Allocate(VAR Pointer:ADDRESS;Size:LONGINT);
  29. (*:Input.       Size: Amount of required memory (Bytes)
  30.   :Output.      Pointer: Address of the allocated memory or
  31.   :Output.      NIL if the allocation failed
  32.   :Semantic.    Allocates memory - Requester is brought up if there's
  33.   :Semantic.    not enough
  34.   :Note.        appends an entry to the memEntry-list of the task
  35.   :Note.        the allocated memory is freed automatically at
  36.   :Note.        Task termination (RemTask() )
  37. *)
  38.  
  39. PROCEDURE AllocMem(VAR Pointer:ADDRESS;Size:LONGINT;Chip:BOOLEAN);
  40. (*:Input.       Size: Amount of required memory (Bytes)
  41.   :Input.       Chip: TRUE: ChipMem required FALSE: doesn't matter which
  42.   :Output.      Pointer: Address of the allocated memory or
  43.   :Output.      NIL if the allocation failed
  44.   :Semantic.    Allocates memory - Requester is brought up if there's
  45.   :Semantic.    not enough
  46.   :Note.        Appends an entry to the memEntry-list of the task
  47. *)
  48.  
  49. PROCEDURE Deallocate(VAR Pointer:ADDRESS);
  50. (*:Input.       Pointer: Address of the memory to be deallocated
  51.   :Output.      Pointer is set to NIL
  52.   :Semantic.    Deallocates Memory blocks allocated with
  53.   :Semantic.    MemSystem.Allocate() or MemSystem.AllocMem()
  54.   :Note.        Breaks if already free memory is deallocated
  55. *)
  56.  
  57. PROCEDURE NoCareAllocate(VAR Pointer:ADDRESS;Size:LONGINT);
  58. (*:Semantic.    The same as Allocate() but this one would rather
  59.   :Semantic.    terminate the Programm than it would return NIL
  60. *)
  61.  
  62. PROCEDURE NoCareAllocMem(VAR Pointer:ADDRESS;Size:LONGINT;Chip:BOOLEAN);
  63. (*:Semantic.    The same as AllocMem() but this one would rather
  64.   :Semantic.    terminate the Programm than it would return NIL
  65. *)
  66.  
  67. PROCEDURE NoCareDeallocate(VAR Pointer:ADDRESS);
  68. (*:Input.       Pointer: Address of the memory to be deallocated
  69.   :Output.      Pointer is set to NIL
  70.   :Semantic.    Deallocates Memory blocks allocated with
  71.   :Semantic.    MemSystem.Allocate() or MemSystem.AllocMem()
  72.   :Note.        Does not complain about freeing memory twice
  73. *)
  74.  
  75. PROCEDURE EnterLevel(VAR Level:LevelKey);
  76. (*:Output.      Level: Key assigned to the new level
  77.   :Semantic.    Creates a new level. (See also ExitLevel() )
  78.   :Note.        The first level is created automatically
  79.   :Note.        during startup, so you needn't EntrerLevel()
  80.   :Note.        at the beginning of your program.
  81. *)
  82.  
  83. PROCEDURE ExitLevel(VAR Level:LevelKey);
  84. (*:Input.       Level: Key assigned by EnterLevel()
  85.   :Semantic.    Deallocates all memory allocated in this
  86.   :Semantic.    or deeper levels.
  87.   :Note.        Notice that each ExitLevel() must follow a corresponding
  88.   :Note.        EnterLevel, whereas not every EnterLevel() must have
  89.   :Note.        a corresponding ExitLevel()
  90. *)
  91.  
  92. END MemSystem.
  93.